Skip to content

Conversation

@leojth
Copy link

@leojth leojth commented Feb 28, 2025

Altitudes are nullable in positions but could not be read because deserialization was done into double[].

This PR fixes this by reading positions using the JSON reader directly, token by token. As a consequence, benchmark shows that reading positions are also slightly faster.

Unit tests are added, not only for reading altitudes but also for reading string literals and numbers as strings (added in PR #19).

Example of GeoJSON that was failing before, but works with the changes in this PR. Note altitude "null" at coordinate 3.

{
    "coordinates": [
        [4.8892593383789062, 52.370725881211314, 10.0],
        [4.8952674865722656, 52.3711451105601, 10.5],
        [4.8920917510986328, 52.369310952782627, null],
        [4.8892593383789062, 52.370725881211314, 10.2]
    ],
    "type": "LineString"
}

@xfischer
Copy link
Member

Sorry for the delays. I'm taking over this PR, I have only one suggestion.
Thank you for this work

@leojth
Copy link
Author

leojth commented Apr 1, 2025

Hi! Thanks for reply. That particular code Math.Abs(x - y) < 0.0000000001; is actually nothing I added and I think it is this number for a reason, looking at the name of the class.

@xfischer
Copy link
Member

xfischer commented Apr 1, 2025

Hi! Thanks for reply. That particular code Math.Abs(x - y) < 0.0000000001; is actually nothing I added and I think it is this number for a reason, looking at the name of the class.

Whops I've missed that, sorry

@xfischer xfischer merged commit 44abb34 into GeoJSON-Net:main Apr 1, 2025
2 checks passed
dmitry-kandiner pushed a commit to dmitry-kandiner/GeoJSON.Text that referenced this pull request Aug 12, 2025
Handle null altitudes when reading positions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants